from snipins import *
import argparse
import sys
import pickle

def expand_file_with_snips(input, output, snips):
  for line in input:
    matches = false_or_first_group(SNIP_INCLUDE_REGEX, line)
    if(matches):
      print 'Found Match'
      if(snips.has_key(matches)):
        output.write(snips[matches])
    else:
      output.write(line)

if __name__ == '__main__':
    # create the parser
    parser = argparse.ArgumentParser(
      description='Compile snips from a file or directory.  This results in one snips file to be used')

    # add the arguments
    parser.add_argument(
        'snip', metavar='snip', type=argparse.FileType('r'), nargs=1,
        help='file containing snips')
    parser.add_argument(
        'input', metavar='input', type=argparse.FileType('r'), nargs=1,
        help='file to be expanded')
    parser.add_argument(
        '-o', '--output', type=argparse.FileType('w'), default=sys.stdout,
        help='expanded version of input file '
             '(default: write the expanded version to stdout)')

    # parse the command line
    args = parser.parse_args()

    expand_file_with_snips(args.input[0], args.output, pickle.load(args.snip[0])) 
